<template>
  <main class="log-item" :style="{ color: color }">
    <div>
      <span class="title" style="font-weight: bold">{{ title }}<br /></span>
      <span style="white-space: pre-line">{{ text }}</span>
    </div>
  </main>
</template>

<script lang="ts" setup>
import { LogLevel } from "./types";
import { ref, watch } from "vue";

enum Status {
  Exception = "rgb(255, 73, 73)",
  Warning = "rgb(230, 162, 60)",
  Normal = "rgb(32, 160, 255)"
}

const color = ref<string>();

const props = defineProps<{
  title: string;
  logLevel: LogLevel;
  text: string;
}>();

const setColor = (newValue: LogLevel) => {
  if (newValue === LogLevel.Error) {
    color.value = Status.Exception;
  } else if (newValue === LogLevel.Warning) {
    color.value = Status.Warning;
  } else if (newValue === LogLevel.Normal) {
    color.value = Status.Normal;
  }
};

watch(() => props.logLevel, setColor);
setColor(props.logLevel);
</script>

<style lang="scss" scoped>
.log-item {
  padding: 4px;
  border: 1px solid rgb(177, 34, 243);
  border-radius: 4px;
  margin-bottom: 5px;
  overflow-wrap: break-word;

  .title {
    width: 130px;
    color: rgb(0, 247, 255);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
  }
}
</style>
